home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vesa_tsr.zip / SAMPLES / VESAPCX.PAS < prev   
Pascal/Delphi Source File  |  1990-10-05  |  24KB  |  864 lines

  1. {-----------------------------------------------------------------------}
  2. {VESAPCX                        GL:01/15/90    }
  3. {-----------------------------------------------------------------------}
  4. {Program for decoding a 4-plane or 8-bit PCX file using the facilities    }
  5. {defined by the VESA Super VGA BIOS Extensions to provide for using    }
  6. {the extended resolutions of a Super VGA card in a hardware independent    }
  7. {manner.  Zsoft's PCX file format was chosen because of its relative    }
  8. {simplicity, so that this demonstration program would not become overly    }
  9. {cluttered with image decoding information.  PCX is the native file    }
  10. {format of Zsoft Paintbrush Plus and other paint programs.        }
  11. {-----------------------------------------------------------------------}
  12. {The following program is written to loosely conform to the VESA     }
  13. {Super VGA BIOS Extension document VS891001.  The program is intended    }
  14. {as a demonstration and is not intended to be an example of a         }
  15. {high-performance implementations of the VESA standard.            }
  16. {                        Gary Lorensen        }
  17. {                        Everex Systems, Inc.    }
  18. {                        48571 Milmont Dr. B3    }
  19. {                        Fremont, CA   94538    }
  20. {-----------------------------------------------------------------------}
  21.  
  22. uses
  23.     dos;
  24.  
  25. {-----------------------------------------------------------------------}
  26.  
  27. const
  28.     rSequAddr = $3C4;
  29.  
  30. {-----------------------------------------------------------------------}
  31.  
  32. type
  33.     ColorType = record
  34.         r,g,b : byte;
  35.     end;
  36.  
  37.     PCXHeaderType = record
  38.         manu : byte;    {10d=0Ah= ZSoft PCX}
  39.     vers : byte;    {0=v2.5,2=v2.8 w/pal,3=v2.8 wo/pal,5=v3.0}
  40.     code : byte;    {1=PCX run length}
  41.     bpp  : byte;    {bits/pixel/plane}
  42.     xmin : word;    {image dimensions}
  43.     ymin : word;
  44.     xmax : word;
  45.     ymax : word;
  46.     hres : word;    {Source device horz res}
  47.     vres : word;    {Source device vert res}
  48.     pal  : array [$00..$0F] of ColorType;
  49.     res0 : byte;    {reserved}
  50.     npln : byte;    {Number of color planes}
  51.     bpl  : word;    {Bytes/scan/plane (usually even)}
  52.     pinf : word;    {Palette info (1=color/BW, 2=gray, 9=????)}
  53.     dpi  : word;    {Scanner dpi or VRes}
  54.     res1 : array [$00..$37] of byte;    {reserved}
  55.     end;
  56.  
  57.     ByteBufferPtrType = ^ByteBufferType;
  58.     ByteBufferType = array [$00..$00] of byte;
  59.  
  60. {-----------------------------------------------------------------------}
  61.  
  62.     s80 = string[80];
  63.     s8  = string[8];
  64.  
  65.     DacType = array [$00..$FF] of ColorType;
  66.  
  67. {-----------------------------------------------------------------------}
  68.  
  69.     CharString = array [$00..$03] of char;
  70.  
  71.     ModeListType = array [$00..$00] of word;
  72.  
  73.     PageFuncPtrType = pointer;
  74.  
  75.     VgaInfoBlockType = record
  76.         VESASignature    : CharString;
  77.     VESAVersion     : word;
  78.     OEMStringPtr    : ^CharString;
  79.     Capabilities    : array [$00..$03] of byte;
  80.     VideoModePtr    : ^ModeListType;
  81.     reserved    : array [$00..$ED] of byte;    {Pad to 256}
  82.     end;
  83.  
  84.     ModeInfoBlockType = record
  85.                      {mandatory information}
  86.     ModeAttributes    : word;
  87.     WinAAttributes    : byte;
  88.     WinBAttributes    : byte;
  89.     WinGranularity    : word;
  90.     WinSize        : word;
  91.     WinASegment    : word;
  92.     WinBSegment    : word;
  93.     WinFuncPtr    : PageFuncPtrType;
  94.     BytesPerScanLine : word;
  95.  
  96.                     {optional information}
  97.     XResolution    : word;
  98.     YResolution    : word;
  99.     XCharSize    : byte;
  100.     YCharSize    : byte;
  101.     NumberOfPlanes    : byte;
  102.     BitsPerPixel    : byte;
  103.     NumberOfBanks    : byte;
  104.     MemoryModel    : byte;
  105.     BankSize    : byte;
  106.     reserved    : array [$00..$E2] of byte;    {Pad to 256}
  107.     end;
  108.  
  109. {-----------------------------------------------------------------------}
  110. {-----------------------------------------------------------------------}
  111.  
  112. var
  113.     reg : Registers;
  114.     VesaVgaInfo : VgaInfoBlockType;
  115.     VesaModeInfo : ModeInfoBlockType;
  116.     prevVesaMode : word;
  117.     VesaMode : word;
  118.     PcxHeader    : PCXHeaderType;
  119.     pcxfile : file;
  120.     pcxfname : s80;
  121.     i,j : word;
  122.     ch : char;
  123.  
  124. {-----------------------------------------------------------------------}
  125. {-----------------------------------------------------------------------}
  126.  
  127. function decval(ch : char) : byte;
  128.  
  129. begin
  130.     decval := 0;
  131.     if ((ch>='0') and (ch<='9')) then
  132.         decval := ord(ch)-ord('0');
  133.     if ((ch>='A') and (ch<='F')) then
  134.         decval := ord(ch)-ord('A')+$0A;
  135.     if ((ch>='a') and (ch<='f')) then
  136.         decval := ord(ch)-ord('a')+$0A;
  137. end;
  138.  
  139. function hex2dec(s : s80) : word;
  140.  
  141. var
  142.     i     : byte;
  143.     tmp   : word;
  144.     place : word;
  145.  
  146. begin
  147.     i := ord(s[0]);
  148.     place := 1;
  149.     tmp := 0;
  150.     while (i>0) do begin
  151.         tmp := tmp+place*decval(s[i]);
  152.     i:=i-1;
  153.     place := place*$10;
  154.     end;
  155.     hex2dec := tmp;
  156. {    writeln('hex2dec(',s,') = ',tmp);}
  157. end;
  158.  
  159. {-----------------------------------------------------------------------}
  160.  
  161. function hexval(x : byte) : char;
  162.  
  163. begin
  164.     hexval := '0';
  165.     if ((x>=0) and (x<=9)) then
  166.         hexval := chr(x+ord('0'));
  167.     if ((x>=10) and (x<=15)) then
  168.         hexval := chr(x-10+ord('A'));
  169. end;
  170.  
  171. function dec2hex(x : word) : s8;
  172.  
  173. var
  174.     tmp   : s8;
  175.     place : word;
  176.  
  177. begin
  178. {    tmp   := '0';}
  179.     tmp := ' ';
  180.     if (x>=$100) then
  181.         place := $1000
  182.     else
  183.         place := $10;
  184.  
  185.     repeat
  186.         tmp := tmp+hexval(x div place);
  187.     x := x mod place;
  188.     place := place div $10;
  189.     until (place=$0000);
  190.  
  191.     dec2hex := tmp+'h';
  192. end;
  193.  
  194.  
  195. function hex(x : word) : s8;
  196.  
  197. var
  198.     tmp   : s8;
  199.     place : word;
  200.  
  201. begin
  202.     tmp := '0';
  203.     if (x>=$100) then
  204.         place := $1000
  205.     else
  206.         place := $10;
  207.  
  208.     repeat
  209.         tmp := tmp+hexval(x div place);
  210.     x := x mod place;
  211.     place := place div $10;
  212.     until (place=$0000);
  213.  
  214.     hex := tmp+'h';
  215. end;
  216.  
  217. function addrhex(x : word) : s8;
  218.  
  219. var
  220.     tmp   : s8;
  221.     place : word;
  222.  
  223. begin
  224.     tmp := '';
  225.     place := $1000;
  226.  
  227.     repeat
  228.         tmp := tmp+hexval(x div place);
  229.     x := x mod place;
  230.     place := place div $10;
  231.     until (place=$0000);
  232.  
  233.     addrhex := tmp;
  234. end;
  235.  
  236. {-----------------------------------------------------------------------}
  237.  
  238. function Min(m,n : longint) : longint;
  239.  
  240. begin
  241.     if (m<n) then
  242.         Min := m
  243.     else
  244.         Min := n;
  245. end;
  246.  
  247. function Max(m,n : longint) : longint;
  248.  
  249. begin
  250.     if (m>n) then
  251.         Max := m
  252.     else
  253.         Max := n;
  254. end;
  255.  
  256. {-----------------------------------------------------------------------}
  257.  
  258. procedure SetVesaBank(win  : byte;
  259.                       bank : byte);
  260.  
  261. var
  262.     reg : Registers;
  263.  
  264. begin
  265.     reg.AX := $4F05;
  266.     reg.BH := $00;
  267.     reg.BL := win;
  268.     reg.DX := bank;
  269.     intr($10,reg);
  270. end;
  271.  
  272. {-----------------------------------------------------------------------}
  273.  
  274. procedure GetVesaBank(win  : byte;
  275.                       var bank : byte);
  276.  
  277. var
  278.     reg : Registers;
  279.  
  280. begin
  281.     reg.AX := $4F05;
  282.     reg.BH := $01;
  283.     reg.BL := win;
  284.     intr($10,reg);
  285.     bank := reg.DX;
  286. end;
  287.  
  288. {-----------------------------------------------------------------------}
  289.  
  290. procedure FindVesaMode(xsize,ysize : word;
  291.                       memmodel : byte;
  292.               bitpixel : byte;
  293.               var bestVesaMode : word;
  294.               var bestVesaModeInfo : ModeInfoBlockType);
  295. var
  296.     tmpVesaModeInfo : ModeInfoBlockType;
  297.     i : byte;
  298.     error : boolean;
  299.  
  300. begin
  301.     i := $00;
  302.     bestVesaMode := $FFFF;
  303.     error := false;
  304.     while ((VesaVgaInfo.VideoModePtr^[i]<>$FFFF) and not(error)) do begin
  305.  
  306.         reg.AX := $4F01;
  307.     reg.CX := VesaVgaInfo.VideoModePtr^[i];
  308.         reg.ES := Seg(tmpVesaModeInfo);
  309.         reg.DI := Ofs(tmpVesaModeInfo);
  310.         intr($10,reg);
  311.  
  312.     error := (reg.AX<>$004F);
  313.  
  314.     if (tmpVesaModeInfo.ModeAttributes and $02=$00) then begin
  315.         case VesaVgaInfo.VideoModePtr^[i] of
  316.             $0100,$0101,$0103,$0105,$0107 : begin
  317.             tmpVesaModeInfo.XCharSize   := 0;
  318.             tmpVesaModeInfo.YCharSize   := 0;
  319.             tmpVesaModeInfo.NumberOfPlanes:= 1;
  320.             tmpVesaModeInfo.BitsPerPixel:= 8;
  321.             tmpVesaModeInfo.NumberOfBanks:= 1;
  322.             tmpVesaModeInfo.MemoryModel := $04;
  323.             tmpVesaModeInfo.BankSize    := 0;
  324.         end;
  325.             $0102,$0104,$0106 : begin
  326.             tmpVesaModeInfo.XCharSize   := 0;
  327.             tmpVesaModeInfo.YCharSize   := 0;
  328.             tmpVesaModeInfo.Number